﻿function GetProductType(objValue)
{
    var itemIndex=parseInt(objValue)+1;    
    var objPic=document.getElementById("SellProductPic");
    var objStock=document.getElementById('ProductStock'); 
    switch(itemIndex)
    {
        case 1:
          objPic.src="../Images/standprice.gif";
          objStock.readOnly=false;
          break;
        case 2:
          objPic.src="../Images/auction.gif";
          objStock.value="1";
          objStock.readOnly=true;
          break;
        case 3:
          objPic.src="../Images/TeamPrice.gif";
          objStock.readOnly=false;
          break;      
        
    } 
    for(var i=1;i<=3;i++)
    {
       document.getElementById('display_productType_'+i).style.display="none";
    }
    document.getElementById('display_productType_'+itemIndex).style.display="";
   
    
}

function SelectCardSet(ctlName){
  var memberCardSet=document.getElementById("memberCard_set");
 if(document.getElementById(ctlName+"_2").checked)
 {
   memberCardSet.style.display="block";
 }
 else
   memberCardSet.style.display="none";
}

function Hidden(hideme)
{
   var H_Table=document.all("table"+hideme);
   H_Table.style.display=H_Table.style.display=="none"?"":"none";
   var H_AAA=document.all("aaa"+hideme);
   H_AAA.title=H_AAA.title=="显示"?"隐藏":"显示";
}     
function ChangeClass()
{  
  var _form=document.forms[0]; 
  _form.action="ShopClassChoose.aspx";
  _form.method="post";
  _form.target="_self";
  _form.submit();
 
} 
function changeTeam(Teamvalue)
{  
   var DisplayIndex=parseInt(Teamvalue);
   var HideIndex=DisplayIndex+1;
   for(var i=1;i<=DisplayIndex;i++)
      document.getElementById("team_"+i).style.display="block";
   for(var j=HideIndex;j<=5;j++)
   {
      document.getElementById("team_"+j).style.display="none";
      //初始化数值
      document.getElementById("TeamPrice"+(6-j)).value="0";
      document.getElementById("TeamNumber"+(6-j)).value="0";
   }
   
}
function changePublisTime()
{  
   var _day=document.getElementById("PublishStartDay");
   var _hour=document.getElementById("PublishStartHour");
   var _min=document.getElementById("PublishStartMin");
   if(!document.getElementById("ProductPublishTime_1").checked)
   {
     _day.disabled=true;
     _hour.disabled=true;
     _min.disabled=true;
   }
   else
   {
     _day.disabled=false;
     _hour.disabled=false;
     _min.disabled=false;
   }
}

function preview()
{
 
  var _form=document.forms[0];
  var old_action=_form.action;
  var old_target=_form.target;
  _form.action="publish_preview.aspx";
  _form.method="post";
  _form.target="_blank";
  _form.submit();
  _form.action=old_action;
  _form.target=old_target;

}
//检测团购设置价格及数量是否合理
function CheckTeamPrice(TeamLevel)
{
   
   
   var _ctlName="";
   var _teamLevel=document.getElementById(_ctlName+"DropTeamNum").value;
   _teamLevel=parseInt(_teamLevel);
   var stockObj=document.getElementById(_ctlName+"ProductStock");
   var originPriceObj=document.getElementById(_ctlName+"OriginallyPrice");   
   var Team5NumberObj=document.getElementById(_ctlName+"TeamNumber5");
   var Team5PriceObj=document.getElementById(_ctlName+"TeamPrice5");
   var team5Price=parseFloat(Team5PriceObj.value);
   var team5Number=parseInt(Team5NumberObj.value);
   var stock=parseInt(stockObj.value);
   var originPrice=parseFloat(originPriceObj.value);
   if(TeamLevel<5)
   {
       
         var NextIndex=parseInt(TeamLevel);
         var PreIndex=parseInt(TeamLevel)+1;
         
         var NextPriceObj=document.getElementById(_ctlName+"TeamPrice"+NextIndex);
         var PrePriceObj=document.getElementById(_ctlName+"TeamPrice"+PreIndex);
         var NextNumberObj=document.getElementById(_ctlName+"TeamNumber"+NextIndex);
         var PreNumberObj=document.getElementById(_ctlName+"TeamNumber"+PreIndex);
         
         var NextPrice=NextPriceObj.value;      
         var NextNumber=NextNumberObj.value;
         var PrePrice=PrePriceObj.value;
         var PreNumber=PreNumberObj.value;
         
         
         if(!isNaN(NextPrice) && !isNaN(NextNumber) &&!isNaN(PrePrice) &&  !isNaN(PreNumber))
         { 
           
            if(parseInt(NextNumber)!=parseFloat(NextNumber))
            {
               document.getElementById("err_TeamName"+NextIndex).innerHTML="请输入数量为整数";  
               NextNumberObj.focus();
               return;
            }
            else if(parseInt(PreNumber)!=parseFloat(PreNumber))
            {
               document.getElementById("err_TeamName"+PreIndex).innerHTML="请输入数量为整数";  
               PreNumberObj.focus();
               return;
            }          
            if(parseInt(NextNumber)>=parseInt(PreNumber))
            {
               document.getElementById("err_TeamName"+NextIndex).innerHTML="档次"+(6-TeamLevel)+"团购数不能超过档次"+(5-TeamLevel)+"的团购数量";              
               NextNumberObj.style.background="#E6FFDD";
               NextNumberObj.focus();
               return;
            }
            else if(parseFloat(NextPrice)<=parseFloat(PrePrice))
            {           
               document.getElementById("err_TeamName"+NextIndex).innerHTML="档次"+(6-TeamLevel)+"价格不能低于档次"+(5-TeamLevel)+"的团购价格";               
               NextPriceObj.style.background="#FFE1E1";
               NextNumberObj.focus();
               return;
            }
            else if(parseFloat(NextPrice)>=originPrice)
            {           
               document.getElementById("err_TeamName"+NextIndex).innerHTML="档次"+(6-TeamLevel)+"价格不能高于原始价";               
               NextPriceObj.style.background="#FFE1E1";
               NextNumberObj.focus();
               return;
            }
            else if(parseFloat(PrePrice)>=originPrice)
            {           
               document.getElementById("err_TeamName"+PreIndex).innerHTML="档次"+(5-TeamLevel)+"价格不能高于原始价";               
               NextPriceObj.style.background="#FFE1E1";
               NextNumberObj.focus();
               return;
            }
            else
            {
               document.getElementById("err_TeamName"+NextIndex).innerHTML="";
              
               NextNumberObj.style.background="white";
               NextPriceObj.style.background="white";
               PrePriceObj.style.background="white";
               PreNumberObj.style.background="white";
            }
         }
         else
         {
            alert("输入非数字字符，请重新输入");
            NextNumberObj.focus();
            return;
         }
   }
   else
   {
     
      if(stockObj.value=="" || stockObj.value=="0")
      {
         alert("商品数量不能为空");
      }
      else
      {
          if(stock<team5Number)
          {
             document.getElementById("err_TeamName5").innerHTML="团购数量不能超过商品数量";
             stockObj.focus();
             return;
          }
          else if(originPrice<=team5Price)
          {
             document.getElementById("err_TeamName5").innerHTML="团购最低价不能大于或等于原始价";
             originPriceObj.focus();
             return;
          }
          else
          {
              document.getElementById("err_TeamName5").innerHTML="";
          }
      }
   }
}
// 显示新的运费选择区域
function displayDeliver(isDisplay) {
	var postageLi = document.getElementById("deliver_template");
	var inputTFClass = "disabled";
	if(isDisplay) {
		postageLi.style.display = "block";
	} else {
		postageLi.style.display = "none";
		
	}

}
function displayUploadVideo(Type)
{
   var linkDiv=document.getElementById('proudct_video_type_url_div');
   var fileDiv=document.getElementById('proudct_video_type_upload_div');
  if(Type=="url")
  {
     linkDiv.style.display='block';
     fileDiv.style.display='none';
   }
   else
   {
      linkDiv.style.display='none';
      fileDiv.style.display='';
   }

}
